﻿using SIPPaser.Mod;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace SIPPaser
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎来到话务分析系统！");
            List<SipMessage> list = new List<SipMessage>(); //承载解析出来的SIP信令包
            //文件读取
            using(var fileread = File.OpenText(@"E:\霸霸的自我修养\通信开发\代码\第二天代码\1.txt"))   //@表示不用进行斜杠转义
            {
                string line = null; //临时变量存储数据
                StringBuilder build = new StringBuilder();  //消息的缓存区
                while ((line= fileread.ReadLine())!=null)   
                {
                    if(!string.IsNullOrEmpty(line)) //不为空
                    {
                        build.AppendLine(line);
                    }
                    else //new sip message
                    {
                        var msgstr = build.ToString();
                        build.Clear();  //清空缓存区
                        //消息解析
                        var msg = SIPPaserTool.PaserMsgStr(msgstr);
                         if(msg!=null)  //返回消息不为空
                        {
                            list.Add(msg);
                            Console.WriteLine(msg.ToString());//打印时间
                        }
                    }
                }
                Console.WriteLine(string.Format("msg count:{0}",list.Count));   //打印解析多少条数据
                Console.ReadLine();
            }
        }
    }
}
